package com.nl.utils.pipeline;

import com.nl.model.model.ResponseVO;
import lombok.extern.slf4j.Slf4j;

/**
 * PipeLineValve.
 *
 * @author dell
 */
@Slf4j
public abstract class PipeLineValve<T extends PipeLineContext> {

    private PipeLineValve next;

    /**
     * 获取下一个阀门.
     *
     * @return Valve 阀门
     */
    PipeLineValve<T> getNext() {
        return next;
    }

    /**
     * 设置下一个阀门.
     *
     * @param pipeLineValve 阀门
     */
    void setNext(final PipeLineValve<T> pipeLineValve) {
        next = pipeLineValve;
    }

    /**
     * 执行管道.
     *
     * @param pipeLineContext 管道上下文
     * @return FlowResult
     */
    public ResponseVO invoke(final T pipeLineContext) {
        PipeLineValve<T> next = getNext();
        if (next == null) {
            return ResponseVO.success();
        }
        if (log.isInfoEnabled()) {
            log.info("执行：{}, 当前时间：{}", next, System.currentTimeMillis());
        }
        return getNext().invoke(pipeLineContext);
    }
}
